﻿using MediatR;
using T_Rbac.Read.APi.Application.Command.Quanxian;
using T_Rbac_Rep.Interface;

namespace T_Rbac.Read.APi.Application.Handlers.Quanxian
{
    public class QuanxianFantianHandlers : IRequestHandler<QuanxianFantianByIdCommand, int[]>
    {
        private readonly IjobMenuesRep ijobMenuesRep;
        private readonly IMenues menues;

        public QuanxianFantianHandlers(IjobMenuesRep ijobMenuesRep, IMenues menues)
        {
            this.ijobMenuesRep = ijobMenuesRep;
            this.menues = menues;
        }

        public async Task<int[]> Handle(QuanxianFantianByIdCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var list = await ijobMenuesRep.GetvaluesByResult(x => x.IsDel == false && x.Jjid == request.id);
                var intlist=new List<int>();
                foreach ( var item in list )
                {
                    var lists = await menues.GetAloneByid(item.Mid);
                    if (lists.Mpid>0)
                    {
                        intlist.Add(lists.Mid);
                    }
                }
                return intlist.ToArray();
            }
            catch (Exception)
            {
                return Array.Empty<int>();
                throw;
            }
           

        }
    }
}
